package com.xingkeduo.business.operation.service;

import com.xingkeduo.business.operation.dao.ShopsMapper;
import com.xingkeduo.dao.database.DatabaseAccessObject;
import com.xingkeduo.pojo.query.ShopsQuery;
import com.xingkeduo.pojo.table.ShopsTable;
import com.xingkeduo.pojo.vo.SeeShopIdVo;
import com.xingkeduo.pojo.vo.ShopsTableVo;
import com.xingkeduo.util.pojo.domain.Page;
import com.xingkeduo.util.tool.CommonUtil;
import com.xingkeduo.util.tool.IdentityUtil;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;

/**
 * 文件概述
 *
 * @author wangxilong <wangxilong@xingkeduo.com>
 * @version id:v0.1 ${date}${time}
 * @package BeautyOS
 * @copyright Copyright (c) XKD 2019
 */
@Component
public class ShopsService {
    private static final String NAMESPACE = ShopsTable.class.getSimpleName();

    @Resource(name = "mysqlOperationDao")
    private DatabaseAccessObject<ShopsTable, ShopsQuery> dao;

    @Resource
    ShopsMapper shopsMapper;
    
    //查询一条
    public ShopsTable selectByCode(long code) throws Throwable {
        ShopsTable shopsTable = dao.select(NAMESPACE, code);
        if (!CommonUtil.isEmpty(shopsTable))
            return shopsTable;
        return null;
    }

    public ShopsTable selectById(long id) throws Throwable {
        ShopsTable shopsTable = dao.select(NAMESPACE, id);
        if (!CommonUtil.isEmpty(shopsTable))
            return shopsTable;
        return null;
    }

    //查询多条
    public List<ShopsTable> selectLists(ShopsQuery shopsQuery) throws Throwable {
        List<ShopsTable> shopsTableList = dao.select(NAMESPACE, shopsQuery);
        if (!CommonUtil.isEmpty(shopsTableList))
            return shopsTableList;
        return null;
    }

    //分页查询
    public Page<ShopsTable> selectPageLists(ShopsQuery shopsQuery, Integer pageNo, Integer pageSize) throws Throwable {
        Page<ShopsTable> servprodTablePage = dao.pageSelect(NAMESPACE,shopsQuery,pageNo,pageSize);
        return servprodTablePage;
    }

    //插入
    public int insert(ShopsTable shopsTable) throws Throwable {
        shopsTable.setCode(IdentityUtil.nextId(IdentityUtil.Worker.USER));
        return dao.insert(NAMESPACE, shopsTable);
    }

    //更新
    public int update(ShopsTable shopsTable) throws Throwable {
        return dao.update(NAMESPACE, shopsTable);
    }

    //删除
    public int delete(ShopsTable shopsTable) throws Throwable {
        return dao.update(NAMESPACE, shopsTable);
    }

    //总条数
    public int count(ShopsQuery shopsQuery) throws Throwable {
        return dao.selectCount(NAMESPACE, shopsQuery);
    }
    
    
    /**
     * 根据坐标获取最近的店铺信息
     * @param shopsQuery
     * @return
     * @throws Throwable
     */
    public List<ShopsTableVo> selectVoListByShopsQuery(ShopsQuery shopsQuery) throws Throwable {
    	return shopsMapper.selectVoListByShopsQuery(shopsQuery);
    }
    
    /**
     * 根据坐标获取最近的店铺信息
     * @param shopsQuery
     * @return
     * @throws Throwable
     */
    public List<ShopsTableVo> pageListVoByShopsQuery(ShopsQuery shopsQuery) throws Throwable {
    	return shopsMapper.pageListVoByShopsQuery(shopsQuery);
    }

    public SeeShopIdVo selectByShopsId(ShopsQuery shopsQuery) throws Throwable {
        return shopsMapper.selectByShopsId(shopsQuery);
    }
}
